package com.org.cys.test.${package};

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.org.cys.pojo.base.Page;
import com.org.cys.service.impl.${package}.${entityName}ServiceImpl;
import com.org.cys.service.${package}.${entityName}Service;
<#list dataList as var>	
import com.org.cys.service.${package}.${var.midEntity}Service;
import com.org.cys.service.${package}.${var.midEntity}Service;
</#list>
import com.org.cys.util.IdWorker;
import com.org.cys.util.PageData;

/*
 * ${entityComment}单元测试
 * @author caiyushen
 */
@RunWith(SpringJUnit4ClassRunner.class)             //表示继承了SpringJUnit4ClassRunner类
@ContextConfiguration(locations = {"classpath:spring-mybatis.xml"})
public class  ${entityName}ServiceTest{
	
	private static Logger logger = Logger.getLogger( ${entityName}ServiceTest.class);
	
	
	@Resource(name = "${entityNameSmall}ServiceImpl")
	private ${entityName}Service ${entityNameSmall}Service;
<#list dataList as var>	
	
	@Resource(name = "${var.midEntitySmall}ServiceImpl")
	private ${var.midEntity}Service ${var.midEntitySmall}Service;
</#list>		
	
	/**
	 * 单元测试
	 * @throws Exception 
	 * */
	@Test
	public void test() throws Exception{
		save();//保存方法
<#list dataList as var>			
		getListBy${var.newColumnBigger}();//根据${var.newColumn}获取${entityName}
		deleteBy${var.newColumnBigger}();
</#list>		
	}
	
	/**
	 * 保存${entityName}
	 * @param PageData
	 * @throws Exception
	 * */
	public PageData save() throws Exception{
		System.out.println("进入save方法");
		PageData pd = new PageData();
<#list dataList as var>			
		List<PageData> ${var.midEntitySmall}List = ${var.midEntitySmall}Service.listAll(pd);
</#list>	
<#list dataList as var>		
		pd.put("${var.newColumn}",${var.midEntitySmall}List.get(0).get("id"));	
</#list>		
		${entityNameSmall}Service.save(pd);
		System.out.println("method-->save(), param--> pd: "+pd.toString());
		return pd;
	}
	
<#list dataList as var>		
	/**
	  * 根据${var.newColumn}获取${entityName}
	  * */
	public List<PageData> getListBy${var.newColumnBigger}() throws Exception{
		System.out.println("进入getListBy${var.newColumnBigger}方法");
		List<PageData> ${var.midEntitySmall}List = ${var.midEntitySmall}Service.listAll(new PageData());
		List<PageData> dataList = ${entityNameSmall}Service.getListBy${var.newColumnBigger}((Long)${var.midEntitySmall}List.get(0).get("id"));
		System.out.println("method-->getListBy${var.newColumnBigger}() dataList.size:"+dataList.size()+" param-> "+${var.midEntitySmall}List.get(0).get("id"));
		return dataList;
	}
	
	/**
	  * 根据${var.newColumn}删除${entityName}
	  * */
	public void deleteBy${var.newColumnBigger}() throws Exception{
		System.out.println("进入deleteBy${var.newColumnBigger}方法");
		List<PageData> ${var.midEntitySmall}List = ${var.midEntitySmall}Service.listAll(new PageData());
		System.out.println("param -> " + ${var.midEntitySmall}List.get(0).get("id"));
		${entityNameSmall}Service.deleteBy${var.newColumnBigger}((Long)${var.midEntitySmall}List.get(0).get("id"));
		getListBy${var.newColumnBigger}();
		System.out.println("method-->deleteBy${var.newColumnBigger} end");
	}
</#list>	
	
}